package net.uman.util;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class PropertiesManager
{
	public static final String CHAIN_ORDER_DESC = "/chainorder-status-desc.properties";
	public static final String SHOP_ORDER_DESC = "/shoporder-status-desc.properties";
	public static final String SHOP_ORDER_STATUS_ICON_MAP = "/shop-status-icon-map.properties";
	public static final String CHAIN_ORDER_STATUS_ICON_MAP = "/chain-status-icon-map.properties";
	public static final String CHAIN_ORDER_RETURNED_REASON = "/chain-order-returned-reason.properties";
	public static final String CHAIN_ORDER_CANCELED_REASON = "/chain-order-canceled-reason.properties";
	public static final String  LOGISTICS_STATUS_ICON_MAP= "/logistics-status-icon-map.properties";
	
	private static Map<String, Properties> map = new HashMap<String, Properties>();
	static
	{
		try {
			InputStream in;
			Properties properties;
			in = PropertiesManager.class.getResourceAsStream(CHAIN_ORDER_DESC);
			try { 
				properties = new Properties();
				properties.load(new InputStreamReader(in, "UTF-8"));
				map.put(CHAIN_ORDER_DESC, properties);
			} finally {
				in.close();
			}
			
			in = PropertiesManager.class.getResourceAsStream(SHOP_ORDER_DESC);
			try { 
				properties = new Properties();
				properties.load(new InputStreamReader(in, "UTF-8"));
				map.put(SHOP_ORDER_DESC, properties);
			} finally {
				in.close();
			}
			
			in = PropertiesManager.class.getResourceAsStream(SHOP_ORDER_STATUS_ICON_MAP);
			try { 
				properties = new Properties();
				properties.load(new InputStreamReader(in, "UTF-8"));
				map.put(SHOP_ORDER_STATUS_ICON_MAP, properties);
			} finally {
				in.close();
			}
			
			in = PropertiesManager.class.getResourceAsStream(CHAIN_ORDER_STATUS_ICON_MAP);
			try { 
				properties = new Properties();
				properties.load(new InputStreamReader(in, "UTF-8"));
				map.put(CHAIN_ORDER_STATUS_ICON_MAP, properties);
			} finally {
				in.close();
			}
			
			in = PropertiesManager.class.getResourceAsStream(CHAIN_ORDER_CANCELED_REASON);
			try { 
				properties = new Properties();
				properties.load(new InputStreamReader(in, "UTF-8"));
				map.put(CHAIN_ORDER_CANCELED_REASON, properties);
			} finally {
				in.close();
			}
			try { 
				in = PropertiesManager.class.getResourceAsStream(CHAIN_ORDER_RETURNED_REASON);
				properties = new Properties();
				properties.load(new InputStreamReader(in, "UTF-8"));
				map.put(CHAIN_ORDER_RETURNED_REASON, properties);
			} finally {
				in.close();
			}
			
			try { 
				in = PropertiesManager.class.getResourceAsStream(LOGISTICS_STATUS_ICON_MAP);
				properties = new Properties();
				properties.load(new InputStreamReader(in, "UTF-8"));
				map.put(LOGISTICS_STATUS_ICON_MAP, properties);
			} finally {
				in.close();
			}
		} catch(Exception e) {
			//TODO
			e.printStackTrace();
		}
	}
	
	public static String getRelatedProperties(String propertiesFileName, String key)
	{
		return map.get(propertiesFileName).getProperty(key);
	}
	public static Properties getChainOrderStatusProperties()
	{
		return map.get(CHAIN_ORDER_DESC);
	}
	public static void refreshPropertiesPool()
	{
		//TODO
	}
	
	public static void cleanPropertiesPool()
	{
		//TODO
	}
	public static void main(String[]_)
	{
		PropertiesManager p = new PropertiesManager();
		List<String> list = Arrays.asList(new String[]{"123", "456"});
		System.out.println(p);
		String[] set = (String[])map.get(CHAIN_ORDER_CANCELED_REASON).keySet().toArray();
		System.out.println(Arrays.asList(set));
		System.out.println(list.size());
	}
//	public static List<String> getChainOrderCancelReasonList()
//	{
//		return Arrays.asList((String[])map.get(CHAIN_ORDER_CANCELED_REASON).keySet().toArray());
//	}
//	public static List<String> getChainOrderReturnedReasonList()
//	{
//		return Arrays.asList((String[])(map.get(CHAIN_ORDER_RETURNED_REASON).keySet().toArray()));
//	}
	public static Set getChainOrderCancelReasonList()
	{
		return map.get(CHAIN_ORDER_CANCELED_REASON).keySet();
	}
	public static Set getChainOrderReturnedReasonList()
	{
		return map.get(CHAIN_ORDER_RETURNED_REASON).keySet();
	}
}
